package edu.fudan.jwxt.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import edu.fudan.jwxt.Exception.ServiceException;
import edu.fudan.jwxt.common.Constants;
import edu.fudan.jwxt.common.RoleConstant;
import edu.fudan.jwxt.utils.UserFormat;
import lombok.Data;



@Data
@TableName("user")
public class User {

    @TableId
    private String uid; //用户学工号
    private String name;    //用户名称
    private String password;    //用户密码
    private String identityId;  //身份证号码
    private String phone;   //电话号码
    private String email;   //电子邮件
    private String role;    //用户身份
    private String status;  //用户状态，判断是否为初次登录，1表示还未登录过系统
    private int majorId;   //专业序号
    private int collegeId; //学院序号

    @TableField(exist = false)
    private String majorName;
    @TableField(exist = false)
    private String collegeName;

    public String ProduceRole(){
        if(getUid().equals(RoleConstant.AdministratorUID) || getUid().equals("00123"))
            return RoleConstant.AdministratorUID;
        else if(UserFormat.IsTeacherID(getUid()))
            return RoleConstant.TeacherStr;
        else if(UserFormat.IsStudentID(getUid()))
            return RoleConstant.StudentStr;
        else
            throw new ServiceException(Constants.CODE_400,"身份错误");

    }

    //管理员身份时为null
//    private  List<Course> courses;  //拥有的课程w
//    private List<Exam> exams;       //拥有的考试

}
